DateUtil = {
	toDate:function (strDate){
		//2012-08-30T09:04:22.794Z
		var arrSplit = strDate.split("T");
		var arrSplit2 = arrSplit[0].split("-");
		var objDate = new Date(eval(arrSplit2[0]),eval(arrSplit2[1]) - 1,eval(arrSplit2[2]));
		
		arrSplit =  arrSplit[1].split(".");
		arrSplit =  arrSplit[0].split(":");
		objDate.setHours(eval(arrSplit[0]));
		objDate.setMinutes(eval(arrSplit[1]));
		objDate.setSeconds(eval(arrSplit[2]));
		
		return objDate;
	},
	strDateToString:function (strDate,strFormat){
		var objDate = DateUtil.toDate(strDate);
		return DateUtil.format(objDate,strFormat);
	},
	format:function (objDate,f){
		
		// a global month names array
		var gsMonthNames = new Array(
		'January',
		'February',
		'March',
		'April',
		'May',
		'June',
		'July',
		'August',
		'September',
		'October',
		'November',
		'December'
		);
		// a global day names array
		var gsDayNames = new Array(
		'Sunday',
		'Monday',
		'Tuesday',
		'Wednesday',
		'Thursday',
		'Friday',
		'Saturday'
		);
		
		 if (!objDate.valueOf())
		        return '&nbsp;';

		    var d = objDate;

		    return f.replace(/(yyyy|mmmm|mmm|MM|dddd|ddd|dd|hh|mm|ss|a\/p)/gi,
		        function($1)
		        {
		            switch ($1)
		            {
		            case 'yyyy': return d.getFullYear();
		            case 'mmmm': return gsMonthNames[d.getMonth()];
		            case 'mmm':  return gsMonthNames[d.getMonth()].substr(0, 3);
		            case 'MM':   return (d.getMonth() + 1).zf(2);
		            case 'dddd': return gsDayNames[d.getDay()];
		            case 'ddd':  return gsDayNames[d.getDay()].substr(0, 3);
		            case 'dd':   return d.getDate().zf(2);
		            case 'HH':   return ((h = d.getHours() % 12) ? h : 12).zf(2);
		            case 'mm':   return d.getMinutes().zf(2);
		            case 'ss':   return d.getSeconds().zf(2);
		            case 'a/p':  return d.getHours() < 12 ? 'a' : 'p';
		            }
		        }
		    );
	}
} ;

Number.prototype.zf = function (len){
	var str = this.toString();
	if(str.length >= len) return str;
	for(var i = len; i > str.length; i-- ){
		str = "0" + str;
	}
	return str;
};

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function substr_utf8_bytes(str, startInBytes, lengthInBytes) {

	
    var resultStr = '';
    var startInChars = 0;
    var flgTrim = true;

    for (bytePos = 0; bytePos < startInBytes; startInChars++) {

        ch = str.charCodeAt(startInChars);
        bytePos += (ch < 256) ? 1 : encode_utf8(str[startInChars]).length;
    }
    end = startInChars + lengthInBytes - 1;

    for (n = startInChars; startInChars <= end; n++) {
        ch = str.charCodeAt(n);
        end -= (ch < 256) ? 1 : encode_utf8(str[n]).length;
        if(typeof(str[n])!="undefined"){
        	resultStr += str[n];
    	}
        else{
        	flgTrim = false;
        	break;
        }
    }
	if(flgTrim) resultStr += "..."; 
    return resultStr;
}





